axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
// response拦截器
axios.interceptors.response.use(function (response) {
        /*
        console.log(response.data);
        console.log(response.status);
        console.log(response.statusText);
        console.log(response.headers);
        console.log(response.config);
        */
        return response;
    },
    function (error) {
        /*
        function (error) {
          if (error.response) {
            // 请求已发出，但服务器响应的状态码不在 2xx 范围内
            console.log(error.response.data);
            console.log(error.response.status);
            console.log(error.response.headers);
          } else {
            // Something happened in setting up the request that triggered an Error
            console.log('Error', error.message);
          }
          console.log(error.config);
        }
        */
        if (error.response) {
            if (error.response.status === 401) {
                Vue.$messagebox.confirm('你可能太长时间没有操作了, 出于安全考虑, 系统拒绝了你的请求。', '身份验证失败', {
                    confirmButtonText: '重新登录',
                    cancelButtonText: '留在此处',
                    type: 'warning',
                    closeOnClickModal: false
                }).then(function (value) {
                    if (value === 'cancel') {
                        return false;
                    }
                    window.location.href = error.response.headers.location;
                });
            } else if (error.response.status === 403) {
                Vue.$messagebox({
                    message: '权限不足',
                    type: 'error',
                    duration: 5 * 1000
                })
            }
        }
        return Promise.reject(error);
    }
);
